package com.swyc.osschat.Test.StreamTest.Controller.Stream;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Stream;

/**
 * @description TODO
 * @Author: z156940l@outlook.com
 * @className ReduceTest
 * @Date: 2022/6/22 9:55
 */
public class ReduceTest {

    public static void main(String[] args) {
        List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
        int result = numbers
                .stream()
                .reduce(0, (subtotal, element) -> subtotal + element);
    }

    private static void test1(){
        List<BigDecimal> bgList = new ArrayList<>();
        for (int i = 1; i <= 100; i++) {
            bgList.add(new BigDecimal(i));
        }
        Stream<BigDecimal> stream = bgList.stream();
        System.out.println(bgList.stream().max(Comparator.comparing(v -> v)).orElse(BigDecimal.ZERO));
        System.out.println(bgList.stream().filter(v -> BigDecimal.ZERO.compareTo(v) == -1).min(Comparator.comparing(v -> v)).orElse(BigDecimal.ZERO));
        System.out.println(bgList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
        System.out.println(bgList.stream().reduce(BigDecimal::min).orElse(BigDecimal.ZERO));
        System.out.println(bgList.stream().reduce(BigDecimal::max).orElse(BigDecimal.ZERO));
    }
}
